<?php
/**
 * Created by PhpStorm.
 * User: CYJiao
 * Date: 6/18/15
 * Time: 15:45
 */

?>
<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/themes/default/default.css">
<link rel="stylesheet" href="<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/plugins/code/prettify.css">
<script src="<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/kindeditor.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/lang/zh_CN.js"></script>
<script src="<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/plugins/code/prettify.js"></script>

<script>
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="content"]', {
				cssPath : '<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/plugins/code/prettify.css',
				uploadJson : '<?php echo CController::createUrl('community/uploadfile'); ?>',
				fileManagerJson : '<?php echo Yii::app()->request->baseUrl; ?>/css/plugins/editer/file_manager_json.php',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						K('form[name=add_content]')[0].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						K('form[name=add_content]')[0].submit();
					});
				},
				afterBlur: function(){this.sync();}
			});
			prettyPrint();
		});

		function toVaild(){
			if($('#title').val() == ''){
				alert('标题不能为空');
				return false;
			}
			if($("input[name='topics[]']:checked").length < 1){
				alert('必须选择一个话题');
				return false;
			}else if($("input[name='topics[]']:checked").length > 3){
				alert('最多选择3个话题');
				return false;
			}

			$.ajax({
	            type: 'POST',
	            url: '<?php echo CController::createUrl('community/save') ;?>',

	            data: {data:$('#add_content').serializeArray()},
	            success: function(data){
	                if(data != ''){
	                    if($('#main-tab').tabs('exists', '文章详情')){
	                		$('#main-tab').tabs('select', '文章详情');
	                		$('#main-tab').tabs('getSelected').panel('refresh','<?php echo CController::createUrl('community/find')?>&article_id='+data.article_id);
	                	}else{
	                		$('#main-tab').tabs('add',{
					            title:'文章详情',
					            content:'<iframe scrolling="auto" frameborder="0"  src="<?php echo CController::createUrl('community/find')?>&article_id='+data.article_id+'" style="width:100%;height:100%;"></iframe>',
					            closable:true
				        	});
				        	
				        	$('#main-tab').tabs('getSelected').panel('refresh','<?php echo CController::createUrl('community/find')?>&article_id='+data.article_id+'&from=list');
	        				$('#main-tab').tabs('getSelected').css('width', 'auto');
	                	}	
	                }else{
	                	alert('发表失败');
	                    
	                }
	            },
	            dataType: 'json'
	        });

	        return false;
		}
		
		function search_title(){
			$('#datagrid').datagrid('load',{
            	title : $('#search_title').val(),
            	url: "<?php echo CController::createUrl('community/listarticle'); ?>"
        	})
		}
		function reflush(){
			$('#datagrid').datagrid('load',{
            	url: "<?php echo CController::createUrl('community/listarticle'); ?>"
        	})
		}

		
		
</script> 

<style>
    #main-tab {
        overflow: auto;
        padding: 0;
        margin: 0;
    }
    #list_content{
    	overflow: auto;
        padding: 0;
        margin: 0;
    }
    #add_content{
    	overflow: auto;
        padding: 0;
        margin: 0;
    }
</style>

<div id="main-tab" class="easyui-tabs" data-options="border:false,fit:true,plain:true">
    <div title="发表文章" data-options="">

    	<div class="easyui-layout" data-options="border:false,fit:true" style="overflow: auto; height: 700px;">
<form method="post" name="add_content" id="add_content" onsubmit="return toVaild()">
			    	<table cellpadding="5">
			    		<tr>
			    			<td>标题:</td>
			    			<td><input class="easyui-textbox" type="text" id ="title" name="title" ></input></td>
			    		</tr>
			    		<tr>
			    			<td>话题:</td>
			    			<td>
			    				<input style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="1" type="checkbox"><span style="display:inline-block;vertical-align: middle;">内科</span>&nbsp;&nbsp;
			    				<input style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="2" type="checkbox"><span style="display:inline-block;vertical-align: middle;">外科</span>
			    				&nbsp;&nbsp;<input  style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="3" type="checkbox"><span style="display:inline-block;vertical-align: middle;">妇科</span>
			    				&nbsp;&nbsp;
			    				<input  style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="4" type="checkbox"><span style="display:inline-block;vertical-align: middle;">儿科</span>
			    				&nbsp;&nbsp;
			    				<input  style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="5" type="checkbox"><span style="display:inline-block;vertical-align: middle;">中医保健</span>
			    				&nbsp;&nbsp;<input  style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="6" type="checkbox"><span style="display:inline-block;vertical-align: middle;">营养美食</span>
			    				&nbsp;&nbsp;<input  style="vertical-align: middle;" class="easyui-checkbox" name="topics[]" value="7" type="checkbox"><span style="display:inline-block;vertical-align: middle;">其他</span>
			    				
			    				
			    			</td>
			    		</tr>
			    		<tr>
			    			<td>内容:</td>
			    			<td><textarea name="content" id="content" style="width:700px;height:280px;"></textarea></td>
			    		</tr>
			    		<tr>
			    	</table>
			    	<div style="margin-left:700px;padding:5px">
			    	<input class="easyui-linkbutton" style="width:50px;height:50px;" type="submit" id="submit" name="submit" value="提交" data-options="iconCls:'icon-save'"/>
			    	
			        </div>
</form>
</div>
    </div>

    <div title="管理文章" id="list_content" data-options="href:'<?php echo CController::createUrl('community/list',array('')) ;?>'">
    </div>
</div>

<script>
	$(document).ready(function(){
		$('.ke-dialog-default .ke-dialog').attr('height','380px');
		$('.ke-dialog-content').attr('height','380px');
		$('.ke-dialog-body').attr('height','380px');
	});
</script>
    	